<?php
	//includes
	require_once 'includes.php';

	//delete all
//	DB::ExecuteSQL("
//		DELETE FROM t_products_details;
//	");
	
	$startTime = microtime() + time();
	
	$yandexMarket = new YandexMarket();
	$products = $yandexMarket->GetSavedProducts($_GET['from'], $_GET['quantity']);
	
	$result = array('success' => 0, 'fail' => 0);
	
	//parse products for details
	echo "<meta charset = 'utf-8' />";
	foreach ($products as $product)
	{
		//product item
		$productItem = $yandexMarket->GetProductDetails($product);
		
		//saves the product into DB
		$saveResult = $productItem->SaveDetails();
		
		//stats
		$result['success'] += $saveResult['success'];
		$result['fail'] += $saveResult['fail'];
	}

	$endTime = microtime() + time();
	
	//totals
	$resultTime = $endTime - $startTime;
	echo "Total time: $resultTime; Success: {$result['success']}; Fail: {$result['fail']}; ";		
	
?>